package com.jeesite.modules.jydq.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.jydq.entity.JydqComparisonRule;
import com.jeesite.modules.jydq.service.JydqComparisonRuleService;

/**
 * 比价规则表Controller
 * @author dong
 * @version 2025-03-20
 */
@Controller
@RequestMapping(value = "${adminPath}/jydq/comparisonRule")
public class JydqComparisonRuleController extends BaseController {

	@Autowired
	private JydqComparisonRuleService jydqComparisonRuleService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public JydqComparisonRule get(String id, boolean isNewRecord) {
		return jydqComparisonRuleService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
//	@RequiresPermissions("jydq:comparisonRule:view")
	@RequestMapping(value = {"list", ""})
	public String list(JydqComparisonRule jydqComparisonRule, Model model) {
		model.addAttribute("jydqComparisonRule", jydqComparisonRule);
		return "modules/jydq/jydqComparisonRuleList";
	}
	
	/**
	 * 查询列表数据
	 */
//	@RequiresPermissions("jydq:comparisonRule:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<JydqComparisonRule> listData(JydqComparisonRule jydqComparisonRule, HttpServletRequest request, HttpServletResponse response) {
		jydqComparisonRule.setPage(new Page<>(request, response));
		Page<JydqComparisonRule> page = jydqComparisonRuleService.findPage(jydqComparisonRule);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
//	@RequiresPermissions("jydq:comparisonRule:view")
	@RequestMapping(value = "form")
	public String form(JydqComparisonRule jydqComparisonRule, Model model) {
		model.addAttribute("jydqComparisonRule", jydqComparisonRule);
		return "modules/jydq/jydqComparisonRuleForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("jydq:comparisonRule:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated JydqComparisonRule jydqComparisonRule) {
		jydqComparisonRuleService.save(jydqComparisonRule);
		return renderResult(Global.TRUE, text("保存比价规则表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("jydq:comparisonRule:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(JydqComparisonRule jydqComparisonRule) {
		jydqComparisonRuleService.delete(jydqComparisonRule);
		return renderResult(Global.TRUE, text("删除比价规则表成功！"));
	}
	
}